package com.xintonghua.bussiness.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.bean.AddProjectBean;
import com.xintonghua.bussiness.util.GlideUtils;
import com.xintonghua.bussiness.util.ImageUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 添加项目
 * Created by zhangxuemei on 2018/3/11.
 */

public class AddListProjectAdapter extends BaseAdapter {
    private Context context;
    private List<AddProjectBean> list;

    public AddListProjectAdapter(Context context, List<AddProjectBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public AddProjectBean getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    public List<AddProjectBean> getList() {
        return list;
    }

    public void setList(List<AddProjectBean> list) {
        this.list = list;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_add_list_project, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        AddProjectBean bean = list.get(position);
        holder.tvName.setText(bean.getName());
        holder.tvPrice.setText(bean.getMoney() + "");
        //holder.tvSaleNum.setText("字段缺失");
        GlideUtils.load(context, holder.imIcon, bean.getImg());
        //ImageUtils.displayImage(bean.getImg(),holder.imIcon);
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.im_icon)
        ImageView imIcon;
        @BindView(R.id.tv_product_name)
        TextView tvName;
        @BindView(R.id.tv_sale_num)
        TextView tvSaleNum;
        @BindView(R.id.tv_price)
        TextView tvPrice;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}

